﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {
    public class TestCache {

        /// <summary>
        /// 
        /// </summary>
        [Fact]
        public void Test_New1 () {
            var obj = new Node ();
            var res = new Cache<int> (obj, 100);

            Assert.Equal (true, res.IsValid);
            Assert.Equal (obj, res.Object);
            Assert.Equal (100, res.Value);
            Assert.Equal (typeof(Node), res.ObjectType);
        }

        /// <summary>
        /// GCによって回収されたオブジェクトのリソース参照が
        /// Invalidになるのを確認するテスト
        /// </summary>
        [Fact]
        public void Test_Invalidate () {
            var obj = new Node ();
            var res = new Cache<int> (obj, 100);

            obj = null;
            System.GC.Collect ();

            Assert.Equal (false, res.IsValid);
            Assert.Equal (null, res.Object);
            Assert.Equal (100, res.Value);
            Assert.Equal (typeof (Node), res.ObjectType);
        }
    }
}
